RFC7: add support for validator plugins - #2396
Conversation
e78f1a5 to
535cfa7
Compare
75693fb to
d94a27f
Compare
justb4
left a comment
There was a problem hiding this comment.
Very useful addition. What I don't understand: in the configuration example a Python Module path is specified like name: path.to.validator. But in plugin.py a name: Python path is defined like:
'validator': {
'GeoJSON': 'pygeoapi.validator.geojson.GeoJSONValidator'
Maybe I did not understand, or is the idea one can also refer by name, like GeoJSON, to a pre-configured validator in plugin.py?
Yes, validators that are shipped "on board" with pygeoapi can be referrred to by a shortname (i.e. |
Ok, suggestion to add this to the documentation, which only mentions/suggests "module path". |
+1, docs updated. |
| LOGGER.debug('Provider is configured for validation') | ||
| LOGGER.debug('Loading validator') | ||
| try: | ||
| v = load_plugin('validator', {'name': p.validator['name']}) |
There was a problem hiding this comment.
JSON schema recompiles at each call, maybe we can cache the compiled schema?
| LOGGER.debug('Validating item') | ||
| try: | ||
| v.validate(request.data) | ||
| except Exception as err: |
There was a problem hiding this comment.
Suggest to raise ValidatorGenericError as err and use err.http_status_code / err.ogc_exception_code because an invalid payload returns 500
| LOGGER.debug('Validating item') | ||
| try: | ||
| v.validate(request.data) | ||
| except Exception as err: |
There was a problem hiding this comment.
a non-JSON body crashes because JSONDecodeError object has no attribute user_msg. Suggest to add more tests to cover these cases
| try: | ||
| v.validate(request.data) | ||
| except Exception as err: | ||
| msg = err.user_msg or 'Item is not valid, please check and validate payload' # noqa |
There was a problem hiding this comment.
Validation details never reach the client, nor even the log line below
Overview
This PR implements RFC7, adding support for validation plugin facilities in support of data validation on item transactions.
Related Issue / discussion
Additional information
RFC7: https://pygeoapi.io/development/rfc/7
Dependency policy (RFC2)
Updates to public demo
Contributions and licensing
(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)